home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / gfa / gfaexprt.lzh / GFAXPERT.LIB / DISK.LST < prev    next >
Encoding:
File List  |  1986-10-19  |  9.9 KB  |  301 lines

  1. ' ****************
  2. ' *** DISK.LST ***
  3. ' ****************
  4. '
  5. DEFWRD "a-z"
  6. '
  7. > PROCEDURE disk.name(drive$,VAR disk.name$)
  8.   ' *** search for name of disk on drive$ (usually "A")
  9.   LOCAL dta.adres%,stat,k
  10.   dta.adres%=FGETDTA()
  11.   stat=FSFIRST(drive$+":\*.*",8)         ! disk-name only (bit 3)
  12.   IF stat=0
  13.     disk.name$=CHAR{dta.adres%+30}
  14.   ELSE IF stat=-33
  15.     disk.name$=""                        ! no name on disk
  16.   ELSE
  17.     ALERT 3,"*** ERROR ***| |after FSFIRST",1,"EXIT",k
  18.     @exit
  19.   ENDIF
  20. RETURN
  21. ' **********
  22. '
  23. > PROCEDURE dir.folders
  24.   ' *** put folders in main directory in array dir.folders$()
  25.   ' *** folders should not have an extension !!
  26.   ' *** (FSFIRST and FSNEXT find both folders and files with bit 4 set)
  27.   ' *** global :  DIR.FOLDERS$()  LAST.FOLDER
  28.   LOCAL n,dta.adres%,stat
  29.   n=0
  30.   ERASE dir.folders$()
  31.   DIM dir.folders$(20)               ! not more than 20 folders
  32.   dta.adres%=FGETDTA()
  33.   stat=FSFIRST("*",16)               ! 1st folder (bit 4 set)
  34.   IF stat=0
  35.     LET dir.folders$(1)=CHAR{dta.adres%+30}
  36.     n=1
  37.   ENDIF
  38.   REPEAT
  39.     stat=FSNEXT()                    ! next folder
  40.     IF stat=0
  41.       INC n
  42.       LET dir.folders$(n)=CHAR{dta.adres%+30}
  43.     ENDIF
  44.   UNTIL stat<>0
  45.   last.folder=n
  46. RETURN
  47. ' **********
  48. '
  49. > PROCEDURE dir.files(path$,ext$)
  50.   ' *** put all files with path path$ and extension ext$ in array dir.files$()
  51.   ' *** global :  DIR.FILES$()  LAST.FILE
  52.   LOCAL n,search$,dta.adres%,stat
  53.   n=0
  54.   ERASE dir.files$()
  55.   DIM dir.files$(50)                    ! not more than 50 files
  56.   IF RIGHT$(path$)="\"
  57.     search$=path$+"*."+ext$
  58.   ELSE
  59.     search$=path$+"\*."+ext$
  60.   ENDIF
  61.   dta.adres%=FGETDTA()
  62.   stat=FSFIRST(search$,0)               ! 1st file
  63.   IF stat=0
  64.     LET dir.files$(1)=CHAR{dta.adres%+30}
  65.     n=1
  66.   ENDIF
  67.   REPEAT
  68.     stat=FSNEXT()                       ! next file
  69.     IF stat=0
  70.       INC n
  71.       LET dir.files$(n)=CHAR{dta.adres%+30}
  72.     ENDIF
  73.   UNTIL stat<>0
  74.   last.file=n
  75. RETURN
  76. ' **********
  77. '
  78. > PROCEDURE disk.space(drive)
  79.   ' *** return data about disk-format from GEMDOS 54 (Dfree)
  80.   ' *** global : TOTAL.CLUSTERS  FREE.CLUSTERS  USED.CLUSTERS  FREE.BYTES
  81.   ' ***          USED.BYTES  SECTOR.BYTES  CLUSTER.BYTES  CLUSTER.SECTORS
  82.   ' ***          TOTAL.SECTORS
  83.   LOCAL buffer$,buffer%
  84.   buffer$=SPACE$(16)
  85.   buffer%=VARPTR(buffer$)
  86.   VOID GEMDOS(&H36,L:buffer%,drive)
  87.   free.clusters=LPEEK(buffer%)
  88.   total.clusters=LPEEK(buffer%+4)
  89.   used.clusters=total.clusters-free.clusters
  90.   sector.bytes=LPEEK(buffer%+8)
  91.   cluster.sectors=LPEEK(buffer%+12)
  92.   total.sectors=total.clusters*cluster.sectors
  93.   cluster.bytes=sector.bytes*cluster.sectors
  94.   free.bytes=free.clusters*cluster.bytes        ! same as DFREE(0)
  95.   used.bytes=used.clusters*cluster.bytes
  96. RETURN
  97. ' **********
  98. '
  99. > PROCEDURE disk.parameter.block(drive)
  100.   ' *** return data about disk-format from DPB-buffer
  101.   ' *** global : SECTOR.BYTES  CLUSTER.SECTORS  CLUSTER.BYTES
  102.   ' ***          DIR.SECTORS  FAT.SECTORS  FAT2.START.SECTOR
  103.   ' ***          DATA.START.SECTOR  DIR.START.SECTOR  DATA.CLUSTERS
  104.   LOCAL dpb.adres%
  105.   dpb.adres%=BIOS(7,drive)
  106.   sector.bytes=DPEEK(dpb.adres%)
  107.   cluster.sectors=DPEEK(dpb.adres%+2)
  108.   cluster.bytes=DPEEK(dpb.adres%+4)
  109.   LET dir.sectors=DPEEK(dpb.adres%+6)
  110.   fat.sectors=DPEEK(dpb.adres%+8)
  111.   fat2.start.sector=DPEEK(dpb.adres%+10)
  112.   LET data.start.sector=DPEEK(dpb.adres%+12)
  113.   LET dir.start.sector=2*fat.sectors+1
  114.   LET data.clusters=DPEEK(dpb.adres%+14)
  115. RETURN
  116. ' **********
  117. '
  118. > PROCEDURE boot.sector(drive)
  119.   ' *** return data about disk-format from Boot-sector
  120.   ' *** global :
  121.   '     BOOT.BRANCH% DISK.NR% SECTOR.BYTES% CLUSTER.SECTORS% RESERVED.SECTORS%
  122.   '     FATS% DIR.MAX% DISK.SECTORS% FAT.SECTORS% TRACK.SECTORS% DISK.SIDES%
  123.   '     DISK.TRACKS% COMMAND.FLAG% LOAD.MODE% FIRST.LOAD.SECTOR% LOAD.SECTORS%
  124.   '     LOAD.ADDRESS%  FAT.ADDRESS%  LOAD.FILE$  BOOT.CHECKSUM%
  125.   '     (all number-variables are 4-byte integers !)
  126.   LOCAL buffer$,buffer%,desktop.format!,p,sum%,n
  127.   buffer$=SPACE$(512)
  128.   buffer%=VARPTR(buffer$)
  129.   ~BIOS(4,0,L:buffer%,1,0,drive)            ! Boot-sector (0) in buffer
  130.   '
  131.   @word(buffer%,*boot.branch%)              ! branch to boot-code
  132.   disk.nr%=PEEK(buffer%+8)+256*PEEK(buffer%+9)+65536*PEEK(buffer%+10) ! serial no.
  133.   @word(buffer%+11,*sector.bytes%)          ! bytes/sector (512)
  134.   cluster.sectors%=PEEK(buffer%+13)         ! sectors/cluster (2)
  135.   @word(buffer%+14,*reserved.sectors%)      ! reserved sectors (1)
  136.   fats%=PEEK(buffer%+16)                    ! number of FATS (2)
  137.   @word(buffer%+17,*dir.max%)               ! maximum files in directory
  138.   @word(buffer%+19,*disk.sectors%)          ! total sectors
  139.   @word(buffer%+22,*fat.sectors%)           ! sectors/FAT
  140.   @word(buffer%+24,*track.sectors%)         ! sectors/track
  141.   @word(buffer%+26,*disk.sides%)            ! 1- of 2-sided disk
  142.   disk.tracks%=INT(disk.sectors%/(track.sectors%*disk.sides%)) ! tracks/disk
  143.   IF MID$(buffer$,31,30)=STRING$(30,"N")
  144.     desktop.format!=TRUE                    ! disk formatted from Desktop
  145.   ENDIF
  146.   IF desktop.format!
  147.     CLR command.flag%,load.mode%,first.load.sector%,load.sectors%
  148.     CLR load.address%,fat.address%,load.file$
  149.   ELSE
  150.     @word(buffer%+30,*command.flag%)        ! flag
  151.     @word(buffer%+32,*load.mode%)           ! 0 = load file ; or sectors
  152.     @word(buffer%+34,*first.load.sector%)   ! 1st sector (load.mode <> 0)
  153.     @word(buffer%+36,*load.sectors%)        ! number of sectors
  154.     @long.word(buffer%+38,*load.address%)   ! load-address for file or sectors
  155.     @long.word(buffer%+42,*fat.address%)    ! address for FAT-buffer
  156.     '
  157.     LET load.file$=MID$(buffer$,47,11)
  158.     IF LEFT$(load.file$)<>CHR$(0) AND load.mode%=0
  159.       p=INSTR(load.file$," ")
  160.       IF p=0
  161.         p=9
  162.       ENDIF
  163.       LET load.file$=LEFT$(load.file$,p-1)+"."+RIGHT$(load.file$,3)
  164.     ELSE
  165.       LET load.file$=""
  166.     ENDIF
  167.   ENDIF
  168.   sum%=0
  169.   FOR n=0 TO 255
  170.     ADD sum%,CARD{buffer%+n*2}
  171.   NEXT n
  172.   boot.checksum%=sum% AND &HFFFF  ! checksum = &H1234 : bootsector executable
  173. RETURN
  174. ' ***
  175. > PROCEDURE word(adres%,p.word%)
  176.   *p.word%=PEEK(adres%)+256*PEEK(adres%+1)
  177. RETURN
  178. ' ***
  179. > PROCEDURE long.word(adres%,p.long%)
  180.   *p.long%=PEEK(adres%)+256*PEEK(adres%+1)+65536*PEEK(adres%+2)+16777216*PEEK(adres%+3)
  181. RETURN
  182. ' **********
  183. '
  184. > PROCEDURE read.sector(drive,sector)
  185.   ' *** put disk-sector in buffer sector$
  186.   ' *** global :  SECTOR$   OK!
  187.   LOCAL buffer%,flag,k
  188.   sector$=SPACE$(512)
  189.   buffer%=VARPTR(sector$)
  190.   flag=BIOS(4,0,L:buffer%,1,sector,drive)
  191.   IF flag<>0
  192.     ALERT 3,"sector is| |NOT loaded !!",1," OK ",k
  193.     ok!=FALSE
  194.   ELSE
  195.     ok!=TRUE
  196.   ENDIF
  197. RETURN
  198. ' **********
  199. '
  200. > PROCEDURE get.cluster.pointers
  201.   ' *** put cluster- and sector-pointers in arrays
  202.   ' *** uses Procedures Disk.space and Disk.parameter.block
  203.   ' *** global :   CLUSTER.POINTER()   SECTOR.POINTER()
  204.   LOCAL drive,fat.buffer$,fat.buffer%,n,data.clus,cluster.byte.nr,cluster.byte
  205.   LOCAL cluster.byte$,previous.byte,previous.byte$,back.nibble$,clus.pointer$
  206.   LOCAL next.byte,next.byte$,front.nibble$,clus.pointer
  207.   drive=GEMDOS(&H19)
  208.   @disk.space(drive)
  209.   ERASE cluster.pointer(),sector.pointer()
  210.   DIM cluster.pointer(total.clusters),sector.pointer(total.clusters)
  211.   @disk.parameter.block(drive)
  212.   fat.buffer$=SPACE$(fat.sectors*512)
  213.   fat.buffer%=VARPTR(fat.buffer$)
  214.   FOR n=0 TO fat.sectors-1
  215.     VOID BIOS(4,0,L:fat.buffer%+n*512,1,n+1,drive)
  216.   NEXT n
  217.   FOR data.clus=1 TO total.clusters
  218.     cluster.byte.nr=TRUNC(data.clus*1.5)+3
  219.     cluster.byte=PEEK(fat.buffer%+cluster.byte.nr-1)
  220.     cluster.byte$=HEX$(cluster.byte)
  221.     IF LEN(cluster.byte$)=1
  222.       cluster.byte$="0"+cluster.byte$
  223.     ENDIF
  224.     IF EVEN(data.clus)
  225.       previous.byte=PEEK(fat.buffer%+cluster.byte.nr-2)
  226.       previous.byte$=HEX$(previous.byte)
  227.       IF LEN(previous.byte$)=1
  228.         previous.byte$="0"+previous.byte$
  229.       ENDIF
  230.       back.nibble$=LEFT$(previous.byte$)
  231.       clus.pointer$=cluster.byte$+back.nibble$
  232.     ELSE
  233.       LET next.byte=PEEK(fat.buffer%+cluster.byte.nr)
  234.       LET next.byte$=HEX$(next.byte)
  235.       IF LEN(next.byte$)=1
  236.         LET next.byte$="0"+next.byte$
  237.       ENDIF
  238.       front.nibble$=RIGHT$(next.byte$)
  239.       clus.pointer$=front.nibble$+cluster.byte$
  240.     ENDIF
  241.     clus.pointer=VAL("&H"+clus.pointer$)
  242.     cluster.pointer(data.clus)=clus.pointer
  243.     sector.pointer(data.clus)=(clus.pointer-2)*2+data.start.sector
  244.   NEXT data.clus
  245. RETURN
  246. ' **********
  247. '
  248. > PROCEDURE get.file.sectors(fat.cluster)
  249.   ' *** call Procedure Get.cluster.pointers first
  250.   ' *** first FAT-pointer has to be extracted from directory !!
  251.   ' *** prints sectors of file
  252.   ' *** first FAT-cluster is no. 2 (pointer of "data-cluster" no. 1 !)
  253.   cluster=cluster.pointer(fat.cluster-1)
  254.   IF cluster<=&HFF8
  255.     sector=sector.pointer(fat.cluster-1)
  256.     PRINT sector'sector+1';
  257.     @get.file.sectors(cluster)
  258.   ENDIF
  259. RETURN
  260. ' **********
  261. '
  262. > PROCEDURE force.mediach
  263.   ' *** a disk-change is not always noticed by GEMDOS
  264.   ' *** use this Procedure if in doubt
  265.   ' *** after (X)BIOS read-routines not necessary after pause of 1.5 second
  266.   ' *** (use PAUSE 75 before GEMDOS reads disk again)
  267.   LOCAL x$,old.vector%,a%
  268.   x$=SPACE$(12)
  269.   old.vector%=LPEEK(&H47E)
  270.   a%=V:x$
  271.   DPOKE a%,&H2B7C
  272.   LPOKE a%+2,old.vector%
  273.   DPOKE a%+6,&H47E
  274.   DPOKE a%+8,&H7002
  275.   DPOKE a%+10,&H4E75
  276.   SLPOKE &H47E,a%
  277.   ~DFREE(0)                 ! current drive
  278. RETURN
  279. ' **********
  280. '
  281. > PROCEDURE check.boot
  282.   ' *** compute checksum of bootsector and warn user if bootsector executable
  283.   LOCAL drive,buffer$,buffer%,sum%,n,m$
  284.   PRINT " Checking boot-sector ..."
  285.   drive=GEMDOS(&H19)
  286.   buffer$=SPACE$(512)
  287.   buffer%=VARPTR(buffer$)
  288.   ~BIOS(4,0,L:buffer%,1,0,drive)    ! bootsector (0) of current drive in buffer
  289.   sum%=0
  290.   FOR n=0 TO 255
  291.     ADD sum%,CARD{buffer%+n*2}
  292.   NEXT n
  293.   sum%=sum% AND &HFFFF
  294.   IF sum%=&H1234
  295.     m$="Bootsector|executable :|this could be|a boot-virus"
  296.     ALERT 3,m$,2," OK |STOP",k
  297.   ENDIF
  298. RETURN
  299. ' **********
  300. '
  301.